package cn.kgc.tongxun.controller;

import cn.kgc.tongxun.pojo.Contact;
import cn.kgc.tongxun.pojo.ResultEntity;
import cn.kgc.tongxun.service.ContactService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class ContactController {

    @Resource
    ContactService contactService;
    @RequestMapping("/sele")
    public ResultEntity<PageInfo<Contact>> sele(@RequestParam(value = "cname",required = false,defaultValue = "")String cname,
                                                @RequestParam(value = "pageNum",required = false,defaultValue = "1")Integer pageNum){
        PageInfo<Contact> pageInfo = contactService.seleContact(cname, pageNum);
    return ResultEntity.successWithoutData(pageInfo);
    }
    @RequestMapping("/add")
    public ResultEntity<String> add(@RequestBody Contact contact){
    try {
        Integer add = contactService.add(contact);
        if(add>0){
            return ResultEntity.successWithoutData("success");
        }else{
            return ResultEntity.successWithoutData("fail");
        }
    }catch (Exception ex){
        return ResultEntity.successWithoutData("fail");
    }

    }
}
